import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.3

//污染效果框
Item
{
    id:pollutionDisperItemSubmenu
    width:pollutionDisperItemBg.width
    height:pollutionDisperItemBg.height
     property alias wind_direction: windDir.pointerS
     property alias wind_speed: windSpeed.pointerY
    transform: Scale { origin.x: 0; origin.y: 0; xScale: root.x_enl-0.3;yScale: root.y_enl-0.3}
    Image
    {
        id:pollutionDisperItemBg
        source:"./切图/态势感知/污染扩散控件底子.png"
        width: 430
        height: 264
        MouseArea{id:pollutionDisperItemBgArea;anchors.fill:parent}
    }
    Text
    {
        id:smoke
        anchors.top: pollutionDisperItemBg.top
        anchors.topMargin: 14
        anchors.left: pollutionDisperItemBg.left
        anchors.leftMargin: 25
        text:"烟雾:"
        font.pixelSize: 14
        color: "white"
        font.family: "微软雅黑"

    }
    Switch
    {
        id:smokeBoxz
        anchors.left: smoke.right
        anchors.leftMargin: 8
        anchors.top: smoke.top
        anchors.topMargin: 5
        checked:true
        style:   SwitchStyle
        {
            groove:Rectangle
            {

                implicitHeight:14
                implicitWidth:40
                color:control.checked?"#15d5b2":"#777777"
                border.color: control.checked?"#15d5b2":"#777777"
                border.width: 1
            }
            handle:Rectangle
            {
                implicitHeight:14
                implicitWidth:21
                //                    color:control.checked?"#ffffff":"#999999"
                color:control.checked?"#eeeeee":"#999999"
                border.color: control.checked?"#15d9b2":"#777777"
                border.width: 1
            }


        }
        onCheckedChanged:
        {
            //开关
            smokeBoxz002.checked = false
            app.slotShowFDCModel(checked)

            if(checked ===false)
            {
                windSpeed.pointerY =0
                windDir.pointerS = 0
            }
        }
    }

    Text
    {
        id:smoke002
        anchors.top: pollutionDisperItemBg.top
        anchors.topMargin: 14
        anchors.left: smokeBoxz.right
        anchors.leftMargin: 25
        text:"影响范围:"
        font.pixelSize: 14
        color: "white"
        font.family: "微软雅黑"

    }
    Switch
    {
        id:smokeBoxz002
        anchors.left: smoke002.right
        anchors.leftMargin: 8
        anchors.top: smoke002.top
        anchors.topMargin: 5
        checked:false
        style:   SwitchStyle
        {
            groove:Rectangle
            {

                implicitHeight:14
                implicitWidth:40
                color:control.checked?"#15d5b2":"#777777"
                border.color: control.checked?"#15d5b2":"#777777"
                border.width: 1
            }
            handle:Rectangle
            {
                implicitHeight:14
                implicitWidth:21
                //                    color:control.checked?"#ffffff":"#999999"
                color:control.checked?"#eeeeee":"#999999"
                border.color: control.checked?"#15d9b2":"#777777"
                border.width: 1
            }


        }
        onCheckedChanged:
        {
            //         开关  checked
            if(smokeBoxz.checked ===true)
            {
                app.slotSmog_Range(checked)
            }
            else
            {
                smokeBoxz002.checked =false
            }
        }
    }




    Image
    {
        id:pollutionDisperItemSubmenuClose
        source:"./切图/排行/关闭.png"
        //            height: 170
//        anchors.top:pollutionDisperItemBg.top
        anchors.top:pollutionDisperItemBg.top
        anchors.right: pollutionDisperItemBg.right
        anchors.topMargin: 10
        anchors.rightMargin: 10
        MouseArea{id:pollutionDisperItemSubmenuArea;anchors.fill:parent
            onClicked:
            {
                pollutionDisperItemSubmenu.visible =false
                app.slotShowFDCModel(false)

            }
        }
    }


Item {
    id: dateChose
    anchors.top:smoke.bottom
    anchors.left: smoke.left
    anchors.topMargin: 20
    anchors.leftMargin: -5
    width: 250
    height: 30
    z: 1
    RowLayout
    {
        anchors.left: parent.left
    Text{
        width: 65
//        color: "white";
        text:" 日期: "
//            horizontalAlignment: Text.AlignHCenter
        font.pixelSize: 14
        color: "white"
        font.family: "微软雅黑"
    }
    MyCalendar{
        id:myCalendar
        x: 70
        implicitWidth:175
        dateValue: (new Date()).toLocaleString(Qt.locale(), "yyyy-MM-dd")
        onDateValueChanged: {
            text = dateValue
            var datu = dateValue +" 00:00:00"
            var dati = app.getFDCdefaValue("410100",datu)
            if(dati.length >0)
            {
                var datt = JSON.parse(dati)
                    var zhi = Math.sqrt(datt.wind_speed)
                    if(zhi >4)
                    {
                        zhi = 4;
                    }
                    wind_speed = zhi*90
                    wind_direction = datt.wind_direction


                    var zhiu =Math.pow(wind_speed/90,2)
                    app.slotSmogDirection(wind_direction)

                    app.slotSmog_WindSpeed(zhiu)

             }
        }
    }

    }
}


    Row
    {
        //        anchors.left: pollutionDisperItemBg.left
        //        anchors.leftMargin: 20
        //        anchors.top: pollutionDisperItemBg.top
        //        anchors.topMargin: 40
        anchors.verticalCenter: pollutionDisperItemBg.verticalCenter
        anchors.horizontalCenter: pollutionDisperItemBg.horizontalCenter
        anchors.verticalCenterOffset: 34
        spacing: 60
        Column
        {
            spacing: 8
            Text
            {
                id:windSpeedText
                text:"风速"
                anchors.horizontalCenter: parent.horizontalCenter
                font.pixelSize: 14
                color: "white"
                font.family: "微软雅黑"

            }
            Item {
                id:windSpeed
                //                anchors.centerIn: parent.Center

                width: background02.width; height: background02.height
                property int pointerY: 0
                Image { id: background02; source: "./切图/态势感知/组-46.png";}


                Image {
                    id:pointImage02
                    x: 52; y: 10
                    source: "./切图/态势感知/指针.png"
                    transform: Rotation {
                        id: hourRotation02
                        origin.x: 11; origin.y: 54;
                        angle: windSpeed.pointerY
                        Behavior on angle {
                            SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
                        }
                    }

                }
                MouseArea {
                    id: mouseArea02

                    anchors.fill: parent
                    hoverEnabled: true
                    //中心点
                    property real cenX02
                    property real cenY02
                    //起始点
                    property real carX02
                    property real carY02
                    //角度
                    property int cenValue02


                    //确定鼠标是不是在项目中
                    property bool handleHovered02: false

                    function updateHandlePosition02(mouse) {
                        var point02  =  windSpeed.mapFromItem(background02,background02.width,background02.height)
                        //中心点  cenX xo,cenY y0,carX x1,cary y1 mouse.x x2., mouse.y y2;
                        cenX02 = point02.x -background02.width/2;
                        cenY02 = point02.y-background02.height/2;
                        carX02 = point02.x -background02.width/2
                        carY02 = point02.y-background02.height;
                        var zzz02 = Math.atan((mouse.y - cenY02)/(mouse.x -cenX02 )) - Math.atan((carY02 - cenY02)/(carX02 -cenX02 ))
                        if(mouse.x >= cenX02)
                        {
                            cenValue02 = zzz02 * 180/Math.PI
                        }
                        else
                        {
                            cenValue02 = (zzz02 * 180/Math.PI) +180
                        }
						var zhi =Math.pow(cenValue02/90,2)
                       
                        windSpeed.pointerY    =  cenValue02
                        //风速

                        app.slotSmog_WindSpeed(zhi)
                    }

                    onPositionChanged: {
                        //坐标位置确定
                        if (pressed)
                        {
                            //鼠标滑动的时候 才会进来
                            updateHandlePosition02(mouse)
                        }
                        //将mouse.X与mouse.y的位置映射到pointImage的坐标系，并返回具有匹配的x和y（以及可选的width和height）属性的对象
                        var pointType02 = mouseArea02.mapToItem(pointImage02, mouse.x, mouse.y)
                        //如果此项目包含点，它在本地坐标中返回true; 否则返回false
                        handleHovered02 = pointImage02.contains(Qt.point(pointType02.x, pointType02.y))
                    }

                    onPressed: {
                        updateHandlePosition02(mouse)
                    }

                    onReleased: {
                        updateHandlePosition02(mouse)
                    }

                    onExited: handleHovered02 = false
                }
            }

        }
        Column
        {
            spacing: 8
            Text
            {
                id:windDirectionText
                anchors.horizontalCenter: parent.horizontalCenter
                text:"风向"
                font.pixelSize: 14
                color: "white"
                font.family: "微软雅黑"

            }

            Item {
                id:windDir
                width: background.width; height: background.height
                property int pointerS: 0
                Image { id: background; source: "./切图/态势感知/组-44.png"; visible:true }


                Image {
                    id:pointImage
                    x: 42; y: 28
                    source: "./切图/态势感知/组-45.png"
                    transform: Rotation {
                        id: hourRotation
                        origin.x: 19; origin.y: 32.5;
                        angle: windDir.pointerS
                        Behavior on angle {
                            SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
                        }
                    }

                }
                MouseArea {
                    id: mouseArea

                    anchors.fill: parent
                    hoverEnabled: true
                    //中心点
                    property real cenX
                    property real cenY
                    //起始点
                    property real carX
                    property real carY
                    //角度
                    property int cenValue


                    //确定鼠标是不是在项目中
                    property bool handleHovered: false

                    function updateHandlePosition(mouse) {
                        var point  =  windDir.mapFromItem(background,background.width,background.height)
                        //中心点  cenX xo,cenY y0,carX x1,cary y1 mouse.x x2., mouse.y y2;
                        cenX = point.x -background.width/2;
                        cenY = point.y-background.height/2;
                        carX = point.x -background.width/2
                        carY = point.y-background.height;

                        var zzz = Math.atan((mouse.y - cenY)/(mouse.x -cenX )) - Math.atan((carY - cenY)/(carX -cenX ))
                        if(mouse.x >= cenX)
                        {
                            cenValue = zzz * 180/Math.PI
                        }
                        else
                        {
                            cenValue = (zzz * 180/Math.PI) +180
                        }
                        windDir.pointerS    =  cenValue
                        app.slotSmogDirection(cenValue)
                    }

                    onPositionChanged: {
                        //坐标位置确定
                        if (pressed)
                        {
                            //鼠标滑动的时候 才会进来
                            updateHandlePosition(mouse)
                        }
                        //将mouse.X与mouse.y的位置映射到pointImage的坐标系，并返回具有匹配的x和y（以及可选的width和height）属性的对象
                        var pointType = mouseArea.mapToItem(pointImage, mouse.x, mouse.y)
                        //如果此项目包含点，它在本地坐标中返回true; 否则返回false
                        handleHovered = pointImage.contains(Qt.point(pointType.x, pointType.y))
                    }

                    onPressed: {
                        updateHandlePosition(mouse)
                    }

                    onReleased: {
                        //                        updateHandlePosition(mouse)
                    }

                    onExited: handleHovered = false
                }
            }

        }
    }
}

